import sm3_hmac
import OpenSSL.SSL
import hmac
from hashlib import sha256
import gmssl.sm4
from gmssl import func
import hashlib
import random
from Crypto.Util import number
from secrets import randbits
import string
# 生成k位的安全参数
def security_parameter_gen(k):
    return randbits(k)

#生成K位的大素数
def get_large_prime(k):
    return number.getPrime(k)

#生成sha-256的密钥，k为传入的安全参数
def sha256_key_gen(k):
    dk = hashlib.pbkdf2_hmac('sha256', b'psswor',k.to_bytes(128,'big'), 100000)
    # dk = hashlib.pbkdf2_hmac('sha256', b'psswor', 100000)
    return dk

def sm4_gen_key(bits):
    #key = random.randbytes(15)
    #key = random.sample('zyxwvutsrqponmlkjihgfedcba1234567890', 5)
    num_set = [chr(i) for i in range(48, 58)]
    char_set = [chr(i) for i in range(97, 123)]
    total_set = num_set + char_set
    key = "".join(random.sample(total_set, bits))
    #key = ''.join(random.sample(string.ascii_letters + string.digits, 15))
    # 这个key要转换为bytes才可以用
    return key










